using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.SqlManagerUI.Scripting;
using Microsoft.SqlServer.Management.UI.VSIntegration;
using System;
using System.Collections.Generic;

namespace Microsoft.SqlServer.Management.SqlManagerUI
{
	internal class GenerateScriptMaker
	{
		private GenWizGeneralData generalData;

		private GenWizOptionsBase optionsData;

		private GenWizGeneralData.ScriptDestination saveScriptOption;

		private string fileName;

		private GenScriptWizForm wizard;

		private List<GenWizObjectType> wizObjectCollection;

		private bool scriptAllObjects;

		private ScriptingDriver _scriptingDriver;

		public ScriptingDriver ScriptingDriver
		{
			get
			{
				return this._scriptingDriver;
			}
		}

		public bool ScriptAllObjects
		{
			get
			{
				return this.scriptAllObjects;
			}
		}

		public GenerateScriptMaker(GenScriptWizForm parent)
		{
			this.wizard = parent;
			this.generalData = (GenWizGeneralData)this.wizard.WizardInputs.FindItem(0);
			this.optionsData = (GenWizOptionsBase)this.wizard.WizardInputs.FindItem(1);
			this.wizObjectCollection = (List<GenWizObjectType>)this.wizard.WizardInputs.FindItem(2);
			this.scriptAllObjects = this.wizard.WizardInputs.FindBool(3);
			this.fileName = this.generalData.SaveFileName;
			this.saveScriptOption = this.generalData.SaveScriptDestination;
			this._scriptingDriver = this.generalData.ScriptingDriver;
			this._scriptingDriver.SchemaQualify = (this.optionsData.SchemaQualify == GenWizOptionsBase.BooleanTypeOptions.True);
			this._scriptingDriver.DataOnly = (this.optionsData.TypeOfDataToScript == GenWizOptionsBase.TypeOfDataToScriptOptions.DataOnly);
			this._scriptingDriver.SchemaOnly = (this.optionsData.TypeOfDataToScript == GenWizOptionsBase.TypeOfDataToScriptOptions.SchemaOnly);
			this._scriptingDriver.DropExistingObjects = (this.optionsData.DropExistingObjects == GenWizOptionsBase.BooleanTypeOptions.True);
			if (this.generalData.SaveScriptDestination == GenWizGeneralData.ScriptDestination.ToProvider)
			{
				this._scriptingDriver.UseTransactionForPublish = (((GenWizPublishOptions)this.optionsData).UseTransactionForPublish == GenWizOptionsBase.BooleanTypeOptions.True);
			}
			if (this.optionsData.ScriptCompatibilityOption == GenWizOptionsBase.ScriptCompatabilityOptions.Script80Compat)
			{
				this._scriptingDriver.TargetServerVersion = SqlServerVersion.Version80;
				return;
			}
			if (this.optionsData.ScriptCompatibilityOption == GenWizOptionsBase.ScriptCompatabilityOptions.Script90Compat)
			{
				this._scriptingDriver.TargetServerVersion = SqlServerVersion.Version90;
				return;
			}
			this._scriptingDriver.TargetServerVersion = SqlServerVersion.Version100;
		}

		internal void DoScript()
		{
			switch (this.saveScriptOption)
			{
			case GenWizGeneralData.ScriptDestination.ToSingleFile:
				this._scriptingDriver.Destination = ScriptDestination.SingleFile;
				break;
			case GenWizGeneralData.ScriptDestination.ToClipboard:
			case GenWizGeneralData.ScriptDestination.ToEditor:
				this._scriptingDriver.Destination = ScriptDestination.SingleScript;
				break;
			case GenWizGeneralData.ScriptDestination.ToFilePerObject:
				this._scriptingDriver.Destination = ScriptDestination.FilePerObject;
				break;
			case GenWizGeneralData.ScriptDestination.ToProvider:
				this._scriptingDriver.Destination = ScriptDestination.PublishToWeb;
				this._scriptingDriver.WebServiceAddress = this.generalData.Provider.WebServiceAddress;
				this._scriptingDriver.WebServicePassword = this.generalData.Provider.Password;
				this._scriptingDriver.WebServiceUserName = this.generalData.Provider.UserName;
				this._scriptingDriver.WebServiceSqlDatabaseName = this.generalData.Database.DatabaseName;
				this._scriptingDriver.WebServiceSqlPassword = this.generalData.Database.Password;
				this._scriptingDriver.WebServiceSqlServerName = this.generalData.Database.ServerName;
				this._scriptingDriver.WebServiceSqlUserName = this.generalData.Database.UserName;
				break;
			}
			this._scriptingDriver.OutputPath = this.fileName;
			IScriptingOptions shellScriptingOptions = this.wizard.ShellScriptingOptions;
			if (this.scriptAllObjects)
			{
				this._scriptingDriver.Urns.Clear();
			}
			this._scriptingDriver.GenerateScript();
			this.wizard.SetProgressAbort(false);
		}

		private void AddItemsFromGenWizObjects(List<GenWizObjectType> genWizObjectTypeCollection)
		{
		}
	}
}
